package Servlet;

import DAO.DAOFactory;
import DAO.OrderDAO;
import javabean.Order;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/OrderManager")
public class OrderManagerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        OrderDAO orderDAO = (OrderDAO) DAOFactory.getOrderDAOInstance();
        List<Order> orders = null;
        try {
            orders = orderDAO.getAllOrder();
            req.setAttribute("orders",orders);
            req.getRequestDispatcher("OrderManager.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
